package com.bw.controller.alipay;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.controller.order.PiOrderController;
import com.bw.entity.alipay.PiPayLog;
import com.bw.entity.order.PiOrder;
import com.bw.resp.ResponseResult;
import com.bw.service.alipay.IPiPayLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yzz
 * @since 2020-06-30
 */
@RestController
@RequestMapping("/paylog")
public class PiPayLogController {
    @Autowired
    private IPiPayLogService logService;

    //定义日志工具
    private final Logger logger = LoggerFactory.getLogger(PiPayLogController.class);

    @PostMapping("/getById/{code}")
    public ResponseResult getById(@PathVariable("code") String code) {
        logger.info("支付日志查询开始");
        ResponseResult re = new ResponseResult(false, 400, "查询失败");
        try {
            QueryWrapper qw = new QueryWrapper();
            if(code!=null){
                qw.eq("out_trade_no",code);
            }
            List<PiPayLog> paylist = logService.list(qw);
            re.setSuccess(true);
            re.setMessage("查询成功");
            re.setCode(200);
            re.setResult(paylist);//存储
            logger.info("支付日志查询结束");
            return re;
        } catch (Exception e) {
            logger.error("支付日志查询失败,{}", e.toString());
            return re;
        }
    }

}
